(define-module (encrypt))

(define-public version-number "0.1")
(define-public email-address "jbranso@dismail.de")

(define-public (print-version program-name)
  (display (string-append program-name " version "
                          version-number "\n")))

(define-public (print-help program-name)
  (display "caesar [options]\n")
  (display "caesar [-s SHIFT] -f FILE \n")
  (display "")
  (display "-v  --version  Display version\n")
  (display "-h, --help     Display this help info\n")
  (display "-f, --file     Specify a file to encrypt.\n")
  (display "-s, --shift    Specify the shift to use.\n")
  (display (string-append "Send bug reports to "
                          email-address "\n")))

(define-public (encrypt shift char)
  (define lower #f)
  (define upper #f)
  (if (char-lower-case? char)
      (begin
        (set! lower #\a)
        (set! upper #\z))
      (begin
        (set! lower #\A)
        (set! upper #\Z)))
  ;; add the shift
  (let ([char (integer->char
               (+ (char->integer char) shift))])
    ;;if after adding the shift, the char is greater than the upper
    ;;char, then we need to tweak things.
    (if (char>? char upper)
        (integer->char
         (let ([lower (char->integer lower)]
               [char  (char->integer char)]
               [upper (char->integer upper)])
           (+ lower
              (- char
                 (+ 1 upper)))))
        char)))
